/**
 * @Author: gan
 * @Description:
 * @File:  redis
 * @Version: 1.0.0
 * @Date: 2022/4/8 2:35 下午
 */

package initialize

import (
	"context"
	"errors"
	"gin-canteen-src/global"
	"github.com/go-redis/redis/v8"
)

func Redis() *redis.Client {
	redisCfg := global.GloConfig.Redis
	client := redis.NewClient(&redis.Options{
		Addr:     redisCfg.Addr,
		Password: redisCfg.Password, // no password set
		DB:       redisCfg.DB,       // use default DB
	})
	pong, err := client.Ping(context.Background()).Result()
	if err != nil {
		_ = errors.New("redis connect ping failed, err:" + err.Error())
	} else {
		_ = errors.New("redis connect ping response:" + pong)
		return client
	}
	return nil
}
